var ChangeManaged = function() {
	return {
		datatable : null,
		/**
		 * 初始状态
		 */
		init : function() {
			this.initListener();
		},
		passwordLevel:function(password) {
        	var modes = [];
        	for (var i = 0; i < password.length; i++) {
        		idx = parseFloat(ChangeManaged.charMode(password.charCodeAt(i)));
        		if(modes.length==0){
        			modes.push(idx);
        		}else{
        			var flags = false;
        			for(var j=0,slen=modes.length;j<slen;j++){
        				if(idx==modes[j]){
        					flags = true;
        				}
        			}
        			if(!flags){
        				modes.push(idx);
        			}
        		}
        	}
        	return modes;//如果不等于6,说明没有同时存在大小写和数字
        },charMode:function (iN) {
		    if(iN >= 48 && iN <= 57){
		    	return 1;
		    }//数字
		    if(iN >= 65 && iN <= 90){
		    	return 2;
		    } //大写字母
		    if(iN >= 97 && iN <= 122){
		    	return 3;
		    } //小写字母
		    return 0;
        },
		/**
		 * 监听开关事件
		 */
		initListener : function() {


			$("#editPassword").click(function(){
				var form1 = $('#addForm');
				form1.validate({
					rules : {
						password : {
							minlength : 5,
							required : true
						},
						repassword:{
							equalTo:'#password',
							minlength : 5,
							required : true
						},
						oldPassword:{
							required : true
						}
					},
				   messages: {
			    	   password: {
			    	    required: "请输入密码",
			    	    minlength: jQuery.format("密码不能小于{0}个字符")
			    	   },
			    	   repassword: {
			    	    required: "请输入确认密码",
			    	    minlength: "确认密码不能小于5个字符",
			    	    equalTo: "两次输入密码不一致"
			    	   }
				   }
				});
				if(form1.valid()){
					
					if(ChangeManaged.passwordLevel($("#password").val()).length<3){//密码等级提示
						
						BootstrapDialog.show({
							type : BootstrapDialog.TYPE_WARNING,
							title : messages.public_cue_warning,
							message : "密码须同时包含数字和大小写字母",
							buttons : [ {
								label : messages.public_cue_sure,
								cssClass : 'btn btn-sm btn-primary',
								action : function(dialogItself) {
									dialogItself.close();
								}
							} ]
						});
						return false;
					}


					var postData = $("form[name='addForm']").serializeJson();
					$.ajax({
						"dataType" : 'json',
						"cache": false,
						"type" : "POST",
						"data" : postData,
						"url" : ctx + "/user/doChangePassword",
						"success" : function(data) {
							if(data.type=='success'){
								BootstrapDialog.show({
									title : messages.public_cue_cue,
									message : messages.public_cue_saveOk,
									buttons : [ {
										label : messages.public_cue_sure,
										cssClass : 'btn btn-sm btn-primary',
										action : function(dialogItself) {
											dialogItself.close();
											window.location.href = ctx+"/logout";
										}
									} ]
								});
								
							}else{
								BootstrapDialog.show({
									type : BootstrapDialog.TYPE_WARNING,
									title : messages.public_cue_warning,
									message : data.message,
									buttons : [ {
										label : messages.public_cue_sure,
										cssClass : 'btn btn-sm btn-primary',
										action : function(dialogItself) {
											dialogItself.close();
										}
									} ]
								});
							}
						}
					});
				}
			});
			
			
			
			$('#userListTable tbody')
				.on('click', 'button[name="del"]',function() {
					var id = $(this).attr("target_id");
					ChangeManaged.del(id);
				});
		}
	};

}();